<layout-header></layout-header>

<nav class="container-xl mb-3">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a routerLink="/welcome">首页</a></li>
        <li class="breadcrumb-item active">用户配置</li>
    </ol>
</nav>

<div class="container-xl mb-3">
    <div class="row justify-content-between">
        <div class="col-12 col-md-4 mb-2 mb-md-0">
            <select class="form-select" [(ngModel)]="formdata.roomid" (change)="getProfiles()">
                <option value="">全部</option>
                <option value="-">私聊</option>
                @for (item of wcfChatrooms | keyvalue; track item.key) {
                <option [value]="item.key">{{item.value.name}}</option>
                }
            </select>
        </div>
        <div class="col-12 col-md-4 mb-2 mb-md-0">
            <select class="form-select" [(ngModel)]="formdata.level" (change)="getProfiles()">
                <option value="0">全部</option>
                @for (item of userLevels | keyvalue; track item.key) {
                <option [value]="item.key">{{item.value.name}}</option>
                }
            </select>
        </div>
        <div class="col-12 col-md-4 text-end">
            <button class="btn btn-primary" [routerLink]="['/profile/create']">添加</button>
        </div>
    </div>
</div>

<div class="container-xl mb-3">
    <table class="table table-hover align-middle">
        <thead class="table-light">
            <tr>
                <th scope="col">#</th>
                <th scope="col">用户</th>
                <th scope="col">场景</th>
                <th scope="col" class="d-none d-md-table-cell">级别</th>
                <th scope="col" class="d-none d-lg-table-cell">AI 模型</th>
                <th scope="col" class="d-none d-xl-table-cell">拉黑期限</th>
                <th scope="col">操作</th>
            </tr>
        </thead>
        <tbody>
            @for (item of profiles; track item.rd) {
            <tr>
                <th scope="row">{{item.rd}}</th>
                <td>
                    @if (item.roomid == '-' && wcfContacts[item.wxid]) {
                    {{wcfContacts[item.wxid].name}}
                    }
                    @if (item.roomid != '-' && wcfRoomMembers[item.roomid] && wcfRoomMembers[item.roomid][item.wxid]) {
                    {{wcfRoomMembers[item.roomid][item.wxid].name}}
                    }
                </td>
                <td>
                    @if (item.roomid == '-') {
                    私聊
                    } @else {
                    {{wcfChatrooms[item.roomid] && wcfChatrooms[item.roomid].name || '-'}}
                    }
                </td>
                <td class="d-none d-md-table-cell">
                    {{userLevels[item.level] && userLevels[item.level].name || '-'}}
                </td>
                <td class="d-none d-lg-table-cell">{{item.ai_model}}</td>
                <td class="d-none d-xl-table-cell">
                    {{item.ban_expire > timestamp ? getLocalTime(item.ban_expire) : '-'}}
                </td>
                <td class="text-nowrap">
                    <button class="btn btn-sm btn-primary me-2" routerLink="/profile/update/{{item.rd}}">编辑</button>
                    <button class="btn btn-sm btn-danger me-2" (click)="deleteProfile(item)">删除</button>
                </td>
            </tr>
            }
        </tbody>
    </table>
</div>